<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('股东/合伙人名称')" prop="partnerName">
            <el-input v-model="form.partnerName" :placeholder="$t('名称')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('合伙人类型')" prop="partnerType">
            <dict-select
              v-model="form.partnerType"
              dictionary="gp_partner_type"
              :placeholder="$t('合伙人类型')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否实际控股人')" prop="whetherControl">
            <dict-select
              v-model="form.whetherControl"
              dictionary="sys_yes_no"
              :placeholder="$t('是否实际控股人')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('股东入股时间')" prop="holderDate">
            <el-date-picker
              v-model="form.holderDate"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('股东入股时间')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('认缴出资额') + $t('金额单位')" prop="subscribeAmount">
            <Money v-model="form.subscribeAmount" unit="w" :placeholder="$t('认缴出资额')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('认缴出资比例(%)')" prop="subscribeRate">
            <Ratio v-model="form.subscribeRate" :placeholder="$t('认缴出资比例(%)')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('实缴出资额') + $t('金额单位')" prop="paidInAmount">
            <Money v-model="form.paidInAmount" unit="w" :placeholder="$t('实缴出资额')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('实缴出资比例(%)')" prop="paidInRate">
            <Money v-model="form.paidInRate" :placeholder="$t('实缴出资比例(%)')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否离开')" prop="whetherLeave">
            <dict-select
              v-model="form.whetherLeave"
              dictionary="sys_yes_no"
              :placeholder="$t('是否离开')"
            />
          </el-form-item>
        </el-col>
        <el-col v-if="form.whetherLeave === 'Y'" :span="12">
          <el-form-item :label="$t('离开时间')" prop="leaveDate">
            <el-date-picker
              v-model="form.leaveDate"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('离开时间')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否有金融牌照')" prop="whetherLicense">
            <dict-select
              v-model="form.whetherLicense"
              dictionary="sys_yes_no"
              :placeholder="$t('是否有金融牌照')"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <FileTable :list.sync="form.fileList" data-type="gp_partner" :business-id="this.$route.query.gpId" :btn-show="!otherBtnHide" />
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="gp:partner" />
    </div>
  </div>
</template>

<script>
import { saveGpPartner, getGpPartner } from '@/api/fund/gp/partner/gpPartner'

export default {
  data() {
    return {
      otherBtnHide: false,
      // 表单参数
      form: {
        fileList: []
      },
      // 遮罩层
      loading: false,
      // 表单校验
      rules: {
        partnerName: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        partnerType: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
        subscribeAmount: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]
      }
    }
  },
  created() {
  },
  methods: {
    // 初始化数据
    init(data) {
      if (data != null && data.id !== undefined) {
        getGpPartner(data.id).then(response => {
          this.form = response.data
        })
      } else {
        this.reset()
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        gpId: this.$route.query.gpId,
        partnerName: undefined,
        partnerType: undefined,
        whetherControl: undefined,
        holderDate: undefined,
        whetherLicense: undefined,
        subscribeAmount: undefined,
        subscribeRate: undefined,
        paidInAmount: undefined,
        paidInRate: undefined,
        whetherLeave: undefined,
        leaveDate: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined,
        remark: undefined,
        fileList: []
      }
      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.formOpen = false
      this.$parent.$parent.reset()
    },
    // 关闭form页面
    closeForm() {
      // 关闭form页面遮罩层
      this.loading = false
      // 关闭form页面
      if (this.$parent.$parent.formOpen !== undefined) {
        this.$parent.$parent.formOpen = false
      }
      // 刷新list页面
      if (this.$parent.$parent.getList !== undefined) {
        this.$parent.$parent.getList()
      }
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          saveGpPartner(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess(this.$t('保存成功'))
              this.closeForm()
            } else {
              this.msgError(response.msg)
            }
            this.loading = false
          })
        } else {
          this.locationError(document)
        }
      })
    }

  }

}
</script>
